/**
 * 工程名: HelloMyFriend
 * 文件名: FragmentMessageList.java
 * 包名: com.stdroom.hellomyfriend.ui
 * 日期: 2013-5-5上午11:06:23
 *
*/

package com.stdroom.hellomyfriend.ui;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;

import com.stdroom.hellomyfriend.MyApplication;
import com.stdroom.hellomyfriend.R;
import com.stdroom.hellomyfriend.adapter.MessageAdapter;
import com.stdroom.hellomyfriend.bean.ShortMessage;
import com.stdroom.hellomyfriend.common.SaxParse;

import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

/**
 * 类名: FragmentMessageList <br/>
 * 功能: TODO 添加功能描述. <br/>
 * 日期: 2013-5-5 上午11:06:23 <br/>
 *
 * @author   "lx"
 * @version  	 
 */
public class FragmentMessageList extends Fragment{

	private ArrayList<ShortMessage> messages = null;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.message_list_layout, container,false);
		ListView messageList = (ListView)view.findViewById(R.id.message_01);
		try {
			Context context = MyApplication.getInstance();
			String path = Environment.getExternalStorageDirectory().getAbsolutePath();
			File file = new File(path+"/message.xml");
			FileInputStream fis = new FileInputStream(file);
//			InputStream inputStream = context.getResources().openRawResource(R.raw.message);
			messages = SaxParse.SaxReadXml(fis);
			MessageAdapter adapter = new MessageAdapter(MyApplication.getInstance().getApplicationContext(),messages);
			messageList.setAdapter(adapter);
		} catch (Exception e) {
			
			e.printStackTrace();
			
		}
		
		return view ;
	}
	
}

